<?php
/**
 * Created by PhpStorm.
 * User: lzy 林子彦
 * Date: 2018/6/1
 * Time: 上午1:20
 */

namespace App\Admin\Repositories;

use App\Admin\Contracts\MemberLevelInterface;
use App\Admin\Models\MemberLevelModel;
use Illuminate\Support\Facades\Request;

/**
 *  权限等级
 * Class DbConfigRepository
 * @package App\Admin\Repositories
 */
class DbMemberLevelRepository implements MemberLevelInterface
{

    /**
     * 获取列表数据
     * @param $where
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|mixed
     */
    public function getList($where){
        return $this->getMemberLevelModel()->newQuery()->where($where)->get();
    }
    /**
     * 等级模型
     * @return MemberLevelModel
     */
    public function getMemberLevelModel(){
        return app()->make( MemberLevelModel::class);
    }

    /**
     * 获取单条信息
     * @param $where
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|mixed|null|object
     */
    public function getInfo($where)
    {
        // TODO: Implement getInfo() method.
        return $this->getMemberLevelModel()->newQuery()->where($where)->first();
    }

    /**
     * 数据操作
     * @param $data
     * @return mixed|void
     */
    public function saveData($data){

        return $this->getMemberLevelModel()->newQuery()->updateOrCreate(["id"=>$data['id']],$data);
    }

    public function deleteData($where){
        return $this->getMemberLevelModel()->newQuery()->where($where)->delete();
    }

    /**
     * 获取列表
     * @param $where
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|mixed
     */
    public function getListAll($where){
        return $this->getMemberLevelModel()->newQuery()->where($where)->get();
    }

    /**
     * 更新统计数据
     * @param $where
     * @param $data
     * @return mixed|void
     */
    public function updateData($where,$data){
        return $this->getMemberLevelModel()->newQuery()->where($where)->update($data);
    }

}